<!DOCTYPE html>
<html>
<head>
    <title>会员注册 {$site_info.site_name|default=''}</title>
    <meta name="keywords" content="{$site_info.site_seo_keywords|default=''}"/>
    <meta name="description" content="{$site_info.site_seo_description|default=''}">
    <include file="public@head_base"/>
    <link rel="stylesheet" href="__TMPL__/public/assets/css/register.css">
</head>

<body class="body-white">

<div class="container shadow">
    <include file="public@nav"/>

    <div class="section" style="padding: 12px;">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li <if condition="$type == 'person'">class="layui-this"</if>>个人会员注册</li>
                <li <if condition="$type == 'company'">class="layui-this"</if>>单位会员注册</li>

            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item <if condition="$type == 'person'">layui-show</if>">
                    <div class="register-form">
                        <form class="layui-form" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">姓名 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" required lay-verify="required" placeholder="请输入标题"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="email" required lay-verify="email" placeholder="请输入标题"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机号 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="tel" name="mobile" required lay-verify="phone" placeholder="请输入手机号"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">验证码 <span style="color: red">*</span></label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="captcha" required lay-verify="required"
                                               placeholder="验证码"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <captcha height="35" width="94" font-size="14"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="password" name="password" required lay-verify="required"
                                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">重复密码 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="password" name="com_password" required lay-verify="required|check"
                                           placeholder="重复密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">工作单位 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="unit" required lay-verify="required"
                                           placeholder="工作单位" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">科室 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="keshi" required lay-verify="required"
                                           placeholder="科室" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">单位地址 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="unit_address" required lay-verify="required"
                                           placeholder="单位地址" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">单位邮编 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="post_code" required lay-verify="required"
                                           placeholder="单位邮编" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">单位电话 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="tel" name="unit_phone" required lay-verify="required"
                                           placeholder="单位电话" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="person">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-tab-item <if condition="$type == 'company'">layui-show</if>">
                    <div class="register-form">
                        <form class="layui-form" action="">

                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="email" required lay-verify="email" placeholder="请输入标题"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="password" name="password" required lay-verify="required"
                                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">重复密码 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="password" name="com_password" required lay-verify="required|check"
                                           placeholder="重复密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">省 市 <span style="color: red">*</span></label>
                                    <div class="layui-input-inline" style="width: 140px;">
                                        <select name="province" lay-verify="required" lay-filter="province">
                                            <foreach name="provinces" item="province">
                                                <option value="{$province.provinceid}">{$province.province}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline" style="width: 140px;">
                                        <select id="city" name="city" lay-verify="required" lay-filter="city">
                                            <foreach name="citys" item="city">
                                                <option value="{$city.cityid}">{$city.city}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline" style="width: 140px;">
                                        <select id="area" name="area" lay-verify="required" lay-filter="area">
                                            <foreach name="areas" item="area">
                                                <option value="{$area.areaid}">{$area.area}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">单位名称 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="unit" required lay-verify="required"
                                           placeholder="单位名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">所属部门 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="bumen" required lay-verify="required"
                                           placeholder="所属部门" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">联系人 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="contact_name" required lay-verify="required"
                                           placeholder="联系人" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机号码 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="tel" name="mobile" required lay-verify="required|phone"
                                           placeholder="手机号码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">固定电话 <span style="color: red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="tel" name="tel" required lay-verify="required"
                                           placeholder="固定电话" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="company">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<!-- /container -->

<include file="public@scripts"/>
<script>
    //Demo
    layui.use(['form', 'laydate', 'element', 'upload'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var element = layui.element;

        form.on("submit(person)", function (data) {
            console.log(data.field);
            if (data.field.com_password != data.field.password) {
                layer.msg("两次密码不一致")
                return false;
            }

            $.post("{:url('user/register/doRegister')}"+"?type=person",data.field,function (res) {
                if(res.code == 1){
                    layer.alert('注册成功',function (index) {
                        window.location.href = res.url;
                    });
                }else {
                    layer.msg(res.msg);
                }
            })
            return false;
        })
        form.on("submit(company)", function (data) {
            console.log(data.field);
            if (data.field.com_password != data.field.password) {
                layer.msg("两次密码不一致");
                return false;
            }

            $.post("{:url('user/register/doRegister')}"+"?type=company",data.field,function (res) {
                if(res.code == 1){
                    layer.alert('注册成功',function (index) {
                        window.location.href = res.url;
                    });
                }else {
                    layer.msg(res.msg);
                }
            })

            return false;
        })
        form.on('select(province)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            loadCity(data.value);
        });
        form.on('select(city)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            loadAreas(data.value);

        });
        form.on('select(area)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象

        });

        function loadCity(province_id) {
            $.get("{:url('user/public/getCity')}", {province_id: province_id}, function (res) {
                if (res.code == 1) {
                    var html = '';
                    for (var i = 0; i < res.data.length; i++) {
                        var item = res.data[i];
                        html += "<option value='" + item.cityid + "'>" + item.city + "</option>"
                    }
                    $("#city").html(html);
                    loadAreas(res.data[0].cityid);
                }
            })
        }

        function loadAreas(city_id) {
            $.get("{:url('user/public/getArea')}", {city_id: city_id}, function (res) {
                if (res.code == 1) {
                    var html = '';
                    for (var i = 0; i < res.data.length; i++) {
                        var item = res.data[i];
                        html += "<option value='" + item.areaid + "'>" + item.area + "</option>"
                    }
                    $("#area").html(html);
                    form.render('select');
                }
            })
        }
    });


</script>
</body>
</html>